package android07.newtop.activity;

import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.data.BeamDataActivity;
import com.jude.easyrecyclerview.EasyRecyclerView;

import android07.newtop.R;
import android07.newtop.model.bean.PictureGallery;
import android07.newtop.presenter.PictureActivityPresenter;
import android07.newtop.utils.MyUtil;

/**
 * 图片页面Activity
 * <p>
 * <p>
 * <p>
 * Created by hy on 2016/10/20
 */
@RequiresPresenter(PictureActivityPresenter.class)
public class PictureActivity extends BeamDataActivity<PictureActivityPresenter,PictureGallery> {
    private static final String TAG = PictureActivity.class.getSimpleName();
    Toolbar toolbar;
    private AppBarLayout appBarLayout;
    public com.jude.easyrecyclerview.EasyRecyclerView easyrecyclerview;
    private android.widget.LinearLayout llroot;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
        setContentView(R.layout.picture_activity);

        initView();


        //设置toolbar
        setSupportActionBar(toolbar);

        AppBarLayout.LayoutParams param = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
        param.setMargins(0, 0, 0, 0);
        toolbar.setLayoutParams(param);
        blur();
    }

    private void initView() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        this.llroot = (LinearLayout) findViewById(R.id.ll_root);
        this.easyrecyclerview = (EasyRecyclerView) findViewById(R.id.easy_recyclerview);
        this.appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
        easyrecyclerview.setErrorView(R.layout.view_net_error);




    }

    /**
     * 添加右上角的菜单按钮集
     * @param menu
     * @return
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.picture_menu, menu);
        return true;
    }

    /**
     * 加载背景磨砂图片
     */
    private void blur() {
        new AsyncTask<Void, Void, Void>() {
            Drawable wallPaperBlurDrawable;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }

            @Override
            protected Void doInBackground(Void... params) {
//                mDensity = getResources().getDisplayMetrics().density;

                wallPaperBlurDrawable = MyUtil.getWallPaperBlurDrawable(PictureActivity.this);
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                llroot.setBackground(wallPaperBlurDrawable);
                super.onPostExecute(aVoid);
            }
        }.execute();
    }

//

    /**
     * 给其他类获得TableLayout的方法
     *
     * @return
     */
    public Toolbar getToolbar() {
        return toolbar;
    }


}
